<?php

declare(strict_types=1);
/**
 * 服务配置中心
 * 1、http 服务器
 * 2、tcp 服务器
 * 3、websocket 服务器
 */
use Hyperf\Server\Server;
use Hyperf\Server\SwooleEvent;

return [
    'mode' => SWOOLE_PROCESS,
    'servers' => [
        [
            'name'      => 'http',
            'type'      => Server::SERVER_HTTP,
            'host'      => '0.0.0.0',
            'port'      => (int)env('SERVER_HTTP_PORT',9401),
            'sock_type' => SWOOLE_SOCK_TCP,
            'callbacks' => [
                SwooleEvent::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'],
            ],
        ],
        [
            'name'      => 'tcp',
            'type'      => Server::SERVER_BASE,
            'host'      => '0.0.0.0',
            'port'      => (int)env('SERVER_TCP_PORT',9402),
            'sock_type' => SWOOLE_SOCK_TCP,
            'callbacks' => [
                SwooleEvent::ON_RECEIVE => [Service\RpcService\RpcTcpServer::class, 'onReceive'],
            ],
            'settings' => [
                'open_eof_check' => true,
                'package_eof' => "\n",
                'package_max_length' => 1024 * 1024 * 2,
                'buffer_output_size' => 32 * 1024 * 1024, //必须为数字
                //'open_length_check'     => true,
                //'package_length_type'   => 'N',
                //'package_length_offset' => 0, //第N个字节是包长度的值
                //'package_body_offset'   => 4, //第几个字节开始计算长度
                //'package_max_length'    => 2000000, //协议最大长度
            ],
        ]
    ],
    'settings' => [
        'enable_coroutine'      => true,
        'worker_num'            => swoole_cpu_num(),
        'pid_file'              => BASE_PATH . '/runtime/hyperf.pid',
        'open_tcp_nodelay'      => true,
        'max_coroutine'         => 100000,
        'open_http2_protocol'   => true,
        'max_request'           => 100000,
        'socket_buffer_size'    => 5 * 1024 * 1024,
        'buffer_output_size'    => 2 * 1024 * 1024,
        'reload_async'          => true,
        'max_wait_time'         => 30,
        'task_worker_num'       => (int)env('SERVER_TASK_WORKER_NUM',300),
        'task_enable_coroutine' => true,
    ],
    'callbacks' => [
        SwooleEvent::ON_BEFORE_START => [App\Event\ConsulServerStartCallback::class, 'beforeStart'],
        SwooleEvent::ON_WORKER_START => [Hyperf\Framework\Bootstrap\WorkerStartCallback::class, 'onWorkerStart'],
        SwooleEvent::ON_PIPE_MESSAGE => [Hyperf\Framework\Bootstrap\PipeMessageCallback::class, 'onPipeMessage'],
        SwooleEvent::ON_WORKER_EXIT => [Hyperf\Framework\Bootstrap\WorkerExitCallback::class, 'onWorkerExit'],
        SwooleEvent::ON_TASK => [Hyperf\Framework\Bootstrap\TaskCallback::class, 'onTask'],
        SwooleEvent::ON_FINISH => [Hyperf\Framework\Bootstrap\FinishCallback::class, 'onFinish'],
    ],
];